package za.ac.wits.elen7045.scraper.models;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import za.ac.wits.elen7045.scraper.interfaces.ScrapeDataPairInterface;
import za.ac.wits.elen7045.scraper.interfaces.ScraperSessionInterface;

/**
 * Storage class to handle specific session returned by scraper service befor
 * processing takes place.
 * 
 * @author Robert
 * 
 */
public class ScraperSession implements ScraperSessionInterface {
	private Date _scraperDate;
	private String _baseUrl;
	private ArrayList<ScrapeDataPairInterface> _dataPairs;

	// TODO call base constructor
	public ScraperSession() {
		_scraperDate = new Date();
		_dataPairs = new ArrayList<ScrapeDataPairInterface>();
	}

	public ScraperSession(Date scraperDate, String baseUrl) {
		_scraperDate = scraperDate;
		_baseUrl = baseUrl;
		_dataPairs = new ArrayList<ScrapeDataPairInterface>();
	}

	public Date getScraperDate() {
		return _scraperDate;
	}
	
	public String getBaseUrl() {
		return _baseUrl;
	}
	
	@Override
	public void addDataPair(ScrapeDataPairInterface result) {
		_dataPairs.add(result);
	}

	@Override
	public ArrayList<ScrapeDataPairInterface> getDataPairs() {
		return _dataPairs;
	}

	public void addAllDataPair(List<ScrapeDataPairInterface> data) {
		_dataPairs.addAll(data);
	}

	@Override
	public String getUrl() {
		// TODO Auto-generated method stub
		return _baseUrl;
	}

	@Override
	public long getDateTime() {
		// TODO Auto-generated method stub
		return _scraperDate.getTime();
	}

	@Override
	public ScrapeDataPairInterface get(String key) {
		// TODO Auto-generated method stub
		for (int i=0, total=_dataPairs.size(); i<total;i++) {
			if (_dataPairs.get(i).getKey().equals(key)) {
				return _dataPairs.get(i);
			}
		}
		return null;
	}
}
